﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Area.SystemManager;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.PoModel.SystemSettings.InstituTions;
using SystemCenterSoa.Service.SystemSettings.InstituTions;

namespace SystemCenterSoa.ApiProject.Area.SystemSettings.InstituTions
{
    [AllowAnonymous]
    public class UserController : SystemManagerBaseController
    {
        private UserService _userService;
        public UserController(UserService userService)
        {
            _userService = userService;
        }
        [HttpGet]
        public ResultModel<List<MajorsManagermentPo>> BindMajors()
        {
            try
            {
                var data = _userService.BindMajors();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<MajorsManagermentPo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<RolesManagermentPo>> BindRoles()
        {
            try
            {
                var data = _userService.BindRoles();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<RolesManagermentPo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<RolePo>> BindRole()
        {
            try
            {
                var data = _userService.BindRole();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<RolePo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<DepartmentOfManagementPo>> BindDep()
        {
            try
            {
                var data = _userService.BindDep();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<DepartmentOfManagementPo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<SetPositionPo>> BindSetPosition()
        {
            try
            {
                var data = _userService.BindSetPosition();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<SetPositionPo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<TechnicalPositionPo>> BindTechnical()
        {
            try
            {
                var data = _userService.BindTechnical();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<TechnicalPositionPo>>(ex);
            }
        }
        [HttpPost]
        public ResultModel<PagerResult<UserManagermentPo>> SearchPage(SearchModel sm)
        {
            try
            {
                
                var data = _userService.SearchPage(sm);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<UserManagermentPo>>(ex);
            }


        }
        [HttpPost]
        public ResultModel<bool> UserMentAdd(UserManagermentPo view)
        {
            try
            {
                var data = _userService.UserMentAdd(view);
                if (data == false) //返回添加id为0,  说明添加没有成功, 直接返回失败
                {
                    return MyFail<bool>("添加没有成功!");
                }
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpGet]
        public ResultModel<UserManagermentPo> GetUserMentById(int id)
        {
            try
            {
                var data = _userService.GetUserMentById(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<UserManagermentPo>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> UserMentUpdate(UserManagermentPo view)
        {
            try
            {
                var data = _userService.UserMentUpdate(view);
                if (data) //如果是成功就更新成功
                {
                    return MyOk(data);

                }
                return MyFail<bool>("更新没有成功!");

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
        [HttpPost]
        public ResultModel<bool> UserMentDelete(string ids)
        {
            try
            {
                var data = _userService.UserMentDelete(ids);
                if (data) //如果是成功就更新成功
                {
                    return MyOk(data);

                }
                return MyFail<bool>("删除没有成功!");

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }
    }
}
